#include "widget.h"
#include "teacher.h"
#include "student.h"
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(500, 300);
    Teacher* t = new Teacher;
    Student* s = new Student;
    // 该方法无法区分是哪个重载的信号函数，也无法区分哪个是重载的槽函数
    // connect(t, &Teacher::say, s, &Student::response);

    // 触发say信号 --->emit
    // emit t->say();

//    auto* btn = new QPushButton("发射", this);
//    btn->move(30 ,30);
//    connect(btn, &QPushButton::clicked,[t](){
//        emit t->say();
//    });

    // 使用SIGNAL()和SLOT()来链接信号和槽
    connect(t, SIGNAL(say(QString)), s, SLOT(response(QString)));
    // emit t->say("放学");

    auto* btn1 = new QPushButton("下课", this);
    btn1->move(30, 30);

    auto* btn2 = new QPushButton("放学", this);
    btn2->move(130, 30);

    connect(btn1, &QPushButton::clicked, [t](){
        emit t->say("下课");
    });

    connect(btn2, &QPushButton::clicked, [t](){
        emit t->say("放学");
    });

    auto* btn3 = new QPushButton("提问", this);
    btn3->move(30, 100);

    auto* btn4 = new QPushButton("老师慢点", this);
    btn4->move(130, 100);

    connect(s, SIGNAL(mySignal(QString)), t, SLOT(mySlot(QString)));

    connect(btn3, &QPushButton::clicked, [s](){
        emit s->mySignal("提问");
    });

    connect(btn4, &QPushButton::clicked, [s](){
        emit s->mySignal("老师慢点");
    });


}

Widget::~Widget()
{

}
